#ifndef _SERVICECONNMANAGER_HXX_
#define _SERVICECONNMANAGER_HXX_

#include "mytypes.h"
#include "mymutex.hxx"
#include "mythread.hxx"
#include "tcpsocket.hxx"
#include "safeque.hxx"
#include "bridgemessage.hxx"

#include <map>
#include <vector>

class AtkConn;
class FileLog;
class BridgeNet;
class AuConnManager;

using namespace std;

/// \brief Thread that manages the creation and destruction of ServiceCon threads.
class AtkConnManager : public Thread
{
public:   
  typedef map<tUInt32, AtkConn*> tAtkConnMap;
  
  AtkConnManager(tUInt32 atkport, FileLog *filelog=0);
  ~AtkConnManager();

  void Shutdown();

  void Send(const tBridgeMsg* bmsg);
  void GetCjhRoot(string& cjhroot, string& clxh) const;

protected:
  void Execute(Thread::Arg arg);

private:
  AtkConnManager(const AtkConnManager &model);

  void ClearConns(bool last = false);
	  
  tUInt32 _atkport;

  tAtkConnMap _atkconn_map;
  Mutex _atkconn_map_mutex;
  
  bool _is_shutdown_requested;
  FileLog *_filelog;
};


#endif // _SERVICECONNMANAGER_HXX_
